package com.tuanzi.loan.business.entity.receipt.user;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

import com.tuanzi.loan.core.entity.AuditEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author Ray 2017/09/21
 */
@Data
@Entity
@Table(name = "TB_LOAN_RECEIPT_SYSTEM_USER")
@EqualsAndHashCode(callSuper = true)
public class ReceiptSystemUser extends AuditEntity {

	private static final long serialVersionUID = 3451625044131316087L;

	@Id
	@GeneratedValue(generator = "uuid2")
	@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
	private String id;

	@NotBlank
	@Length(max = 200)
	@Column(name = "NAME")
	private String name;

	@Length(max = 36)
	@Column(name = "PARENT")
	private String parent;

	@NotBlank
	@Length(max = 200)
	@Column(name = "ACCOUNT")
	private String account;

	@NotBlank
	@Length(max = 200)
	@Column(name = "PWD")
	private String pwd;

	@Length(max = 200)
	@Column(name = "ORGANIZATION")
	private String organization;

	@Email
	@Length(max = 200)
	@Column(name = "EMAIL")
	private String email;

	@Length(max = 20)
	@Column(name = "PHONE")
	private String phone;

	@Length(max = 20)
	@Column(name = "WECHAT")
	private String weChat;

	@NotNull
	@Range(min = 0, max = Integer.MAX_VALUE)
	@Column(name = "RETRY_TIMES")
	private Integer retryTimes;

	@Column(name = "LAST_LOGIN_TIME")
	private Date lastLoginTime;

	@NotNull
	@Column(name = "STATUS")
	private ReceiptSystemUserStatus status;

	@Length(max = 500)
	@Column(name = "REMARK")
	private String remark;

	@NotNull
	@Column(name = "BALANCE")
	private BigDecimal balance;

	public boolean isNormal() {
		return status == ReceiptSystemUserStatus.NORMAL;
	}

	public boolean isDisabled() {
		return status == ReceiptSystemUserStatus.DISABLED;
	}

	public boolean isApproving() {
		return status == ReceiptSystemUserStatus.APPROVING;
	}

	public boolean isLocked() {
		return status == ReceiptSystemUserStatus.LOCKED;
	}

}
